package com.example.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.json.JSONUtil;
import com.example.dao.entity.RuleSceneDebugDO;
import com.example.dao.mapper.RuleSceneDebugMapper;
import com.example.vo.RuleSceneDebugRespVO;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author Houger.
 * @date 2025年01月09日 11:00.
 */
@Service
public class RuleSceneDebugService {

    @Resource
    private RuleSceneDebugMapper ruleSceneDebugMapper;

    public RuleSceneDebugRespVO get(Long id) {
        return ruleSceneDebugMapper.selectSceneDebug(id);
    }

    public RuleSceneDebugRespVO getOne(Long id) {
        RuleSceneDebugDO ruleSceneDebugDO = ruleSceneDebugMapper.selectById(id);
        @SuppressWarnings("all")
        Map<String, String> params = JSONUtil.toBean(ruleSceneDebugDO.getParams(), Map.class);
        List<Object> data = JSONUtil.toList(ruleSceneDebugDO.getData(), Object.class);
        RuleSceneDebugRespVO vo = BeanUtil.copyProperties(ruleSceneDebugDO, RuleSceneDebugRespVO.class, "params", "data");
        vo.setParams(params);
        vo.setData(data);
        return vo;
    }
}
